import HTMLParser
import urllib
import re

urlString = "http://wix.nzix.net/peers.html"
urlText=[]
check=False

class ParseIXP(HTMLParser.HTMLParser):
    def handle_starttag(self,tag,attrs):
        global check
        if tag=="a":
            check=True
                
    def handle_data(self, data):
        global check 
        if data!='\n' and check==True:
            if (re.search("^AS\d\d*", data)):
                 data=data.lstrip("AS")
                 if data not in urlText:
                    urlText.append(data)
        check=False
                    
lparser=ParseIXP()
lparser.feed(urllib.urlopen(urlString).read())
filePath="ixp_members.txt"
file=open(filePath, "a")
for item in urlText:
    #print item
    print >> file, "155 %s" % item
file.close()